﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace GPMS.DbInit
{
    using GPMS.Model;
    using GPMS.Web;
    using EFCachingProvider;
    using EFCachingProvider.Web;
    using EFCachingProvider.Caching;
    class Program
    {
        
        static void Main(string[] args)
        {
            GPMSDbContainer gpms = new GPMSDbContainer();
            AddHelper helper = new AddHelper(gpms);
            //Type[] types = Assembly.Load("GPMS.Web").GetTypes();
            //Type actionType = typeof(System.Web.Mvc.ActionResult);
            //foreach (Type type in types)
            //{
            //    if (type.Namespace == "GPMS.Web.Controllers" && type.IsSubclassOf(typeof(GPMS.Web.Controllers.BaseController)))
            //    {
            //        Console.WriteLine(type.Name);
            //        Console.WriteLine("-----------------------------------------------");
            //        foreach (MethodInfo method in type.GetMethods())
            //        {
            //            if (Check(method, actionType))
            //            {
            //                Console.WriteLine(method.Name + "_" + method.ReturnType.Name);
            //            }
            //        }
            //        Console.WriteLine("-----------------------------------------------");

            //    }
            //}
            helper.AddMvcImformations();
            helper.ShowMvcImformations();
            helper.AddAdmin();
            helper.AddLink();
            Console.WriteLine("All peocess done!");
            Console.ReadKey();
        }

        static bool Check(MethodInfo method, Type type)
        {
            var returnType = method.ReturnType.FullName == type.FullName;
            var returnBase = false;
            if (method.ReturnType.BaseType != null)
            {
                returnBase = method.ReturnType.BaseType.FullName == type.FullName;
            }
            return method.IsPublic && (returnType || returnBase);
        }

        ///// <summary>
        ///// 添加固定的controller & action,作废
        ///// </summary>
        //static void Administrator()
        //{
        //    ControllerInfo controller = new ControllerInfo()
        //    {
        //        ControllerName = "Administrator",
        //        Description = "后台管理",
        //    };
        //    ControllerInfo c = helper.AddController(controller);
        //    List<ActionInfo> actions = new List<ActionInfo>()
        //    {
        //        new ActionInfo(c.ControllerID){ ActionName="Index", Description="后台管理首页"},
        //        new ActionInfo(c.ControllerID){ ActionName="ListUser", Description="显示所有用户信息"},
        //        new ActionInfo(c.ControllerID){ ActionName="EditUser", Description="后台修改用户信息"},
        //        new ActionInfo(c.ControllerID){ ActionName="DeleteUser", Description="删除用户"},
        //        new ActionInfo(c.ControllerID){ ActionName="ListRole", Description="显示所有角色"},
        //        new ActionInfo(c.ControllerID){ ActionName="CreateRole", Description="创建角色"},
        //        new ActionInfo(c.ControllerID){ ActionName="EditRole", Description="修改角色"},
        //        new ActionInfo(c.ControllerID){ ActionName="CreateCategory", Description="创建用户类别"},
        //        new ActionInfo(c.ControllerID){ ActionName="DeleteCategory", Description="删除用户类别"},
        //        new ActionInfo(c.ControllerID){ ActionName="EditCategory", Description="修改用户类别"},
        //        new ActionInfo(c.ControllerID){ ActionName="CreateSpecialty", Description="创建专业"},
        //        new ActionInfo(c.ControllerID){ ActionName="DeleteSpecialty", Description="删除专业"},
        //        new ActionInfo(c.ControllerID){ ActionName="EditSpecialty", Description="修改专业"},
        //    };
        //    helper.AddActions(actions);
        //}
    }
}
